38:265 Applied Quantitative Methods in Geography - 2025
alex-koiter
@Alex_Koiter@sciencemastodon.com
@alex_koiter
alexkoiter.ca
Compiled: 2025-03-28
Create and name a new folder
Open RStudio
Create R project
Create new R script
ggfortify provides plotting tools for commonly used statistics
Add it to the top with the others
ggplot2 to create a figure
When both x and y are continuous we have a simple linear regression
Response variable (y)
Explanatory variable (x)
plant_gr data frame.autoplot() function is part of the ggfortify packagesmooth.colour = NA argument suppresses the “wiggly” line that is a locally weighted regression line.
(e.g., Bartlett, Levene, Shapiro-Wilk, Kolmogorov-Smirnov, Anderson-Darling…)
I generally recommend NOT doing this
summary() function to help us out
Call:
lm(formula = plant.growth.rate ~ soil.moisture.content, data = plant_gr)
Residuals:
Min 1Q Median 3Q Max
-8.9089 -3.0747 0.2261 2.6567 8.9406
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 19.348 1.283 15.08 <2e-16 ***
soil.moisture.content 12.750 1.021 12.49 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.019 on 48 degrees of freedom
Multiple R-squared: 0.7648, Adjusted R-squared: 0.7599
F-statistic: 156.1 on 1 and 48 DF, p-value: < 2.2e-16
Model
Call:
lm(formula = plant.growth.rate ~ soil.moisture.content, data = plant_gr)
Residuals:
Min 1Q Median 3Q Max
-8.9089 -3.0747 0.2261 2.6567 8.9406
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 19.348 1.283 15.08 <2e-16 ***
soil.moisture.content 12.750 1.021 12.49 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.019 on 48 degrees of freedom
Multiple R-squared: 0.7648, Adjusted R-squared: 0.7599
F-statistic: 156.1 on 1 and 48 DF, p-value: < 2.2e-16Effects
Call:
lm(formula = plant.growth.rate ~ soil.moisture.content, data = plant_gr)
Residuals:
Min 1Q Median 3Q Max
-8.9089 -3.0747 0.2261 2.6567 8.9406
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 19.348 1.283 15.08 <2e-16 ***
soil.moisture.content 12.750 1.021 12.49 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.019 on 48 degrees of freedom
Multiple R-squared: 0.7648, Adjusted R-squared: 0.7599
F-statistic: 156.1 on 1 and 48 DF, p-value: < 2.2e-16R2 and adjusted R2
Call:
lm(formula = plant.growth.rate ~ soil.moisture.content, data = plant_gr)
Residuals:
Min 1Q Median 3Q Max
-8.9089 -3.0747 0.2261 2.6567 8.9406
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 19.348 1.283 15.08 <2e-16 ***
soil.moisture.content 12.750 1.021 12.49 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.019 on 48 degrees of freedom
Multiple R-squared: 0.7648, Adjusted R-squared: 0.7599
F-statistic: 156.1 on 1 and 48 DF, p-value: < 2.2e-16Estimate
Std. Error
t value
Pr(>|t|)
Call:
lm(formula = plant.growth.rate ~ soil.moisture.content, data = plant_gr)
Residuals:
Min 1Q Median 3Q Max
-8.9089 -3.0747 0.2261 2.6567 8.9406
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 19.348 1.283 15.08 <2e-16 ***
soil.moisture.content 12.750 1.021 12.49 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.019 on 48 degrees of freedom
Multiple R-squared: 0.7648, Adjusted R-squared: 0.7599
F-statistic: 156.1 on 1 and 48 DF, p-value: < 2.2e-16Slope: 12.75
Call:
lm(formula = plant.growth.rate ~ soil.moisture.content, data = plant_gr)
Residuals:
Min 1Q Median 3Q Max
-8.9089 -3.0747 0.2261 2.6567 8.9406
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 19.348 1.283 15.08 <2e-16 ***
soil.moisture.content 12.750 1.021 12.49 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.019 on 48 degrees of freedom
Multiple R-squared: 0.7648, Adjusted R-squared: 0.7599
F-statistic: 156.1 on 1 and 48 DF, p-value: < 2.2e-16Slope: 12.75
Intercept: 19.35
Call:
lm(formula = plant.growth.rate ~ soil.moisture.content, data = plant_gr)
Residuals:
Min 1Q Median 3Q Max
-8.9089 -3.0747 0.2261 2.6567 8.9406
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 19.348 1.283 15.08 <2e-16 ***
soil.moisture.content 12.750 1.021 12.49 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.019 on 48 degrees of freedom
Multiple R-squared: 0.7648, Adjusted R-squared: 0.7599
F-statistic: 156.1 on 1 and 48 DF, p-value: < 2.2e-16Slope: 12.75
Intercept: 19.35
r2: 0.76
Call:
lm(formula = plant.growth.rate ~ soil.moisture.content, data = plant_gr)
Residuals:
Min 1Q Median 3Q Max
-8.9089 -3.0747 0.2261 2.6567 8.9406
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 19.348 1.283 15.08 <2e-16 ***
soil.moisture.content 12.750 1.021 12.49 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.019 on 48 degrees of freedom
Multiple R-squared: 0.7648, Adjusted R-squared: 0.7599
F-statistic: 156.1 on 1 and 48 DF, p-value: < 2.2e-16y = mx + b
Confidence interval
new_data <- data.frame(soil.moisture.content = 1)
predict(model_pgr, newdata = new_data,
interval = "confidence", level = 0.95) fit lwr upr
1 32.098 30.92568 33.27031
new_data <- data.frame(soil.moisture.content = 1)
predict(model_pgr, newdata = new_data,
interval = "predict", level = 0.95) fit lwr upr
1 32.098 23.93247 40.26352
Does flipper length, bill depth, and bill length in penguins vary with body mass?
Each student is going to do something slightly different!
We need to filter the data by penguin species
or
Struggling to get your desired colours or text size? Please ask!
The plot preview may look different the the saved version.
Additionally
Thank you!
alexkoiter.ca
koitera@brandonu.ca
Slides created with Quarto on 2025-03-28